package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.*; 
	import flash.utils.Timer;
	
	public class PoolTest extends Sprite
	{
		public function PoolTest()
		{
			const MAX_SPRITEST:uint = 100;
			const GROWTH_VALUET:uint = MAX_SPRITEST >> 1;
			const MAX_NUMT:uint = 10;
			
			SpritePool.initialize(MAX_SPRITEST, GROWTH_VALUET);
			
			var currentSprite:Sprite;
			var container:Sprite = SpritePool.getSprite();
			
			addChild(container);
			
			for(var i:int = 0; i < MAX_NUMT; i++)
			{
				for(var j:int = 0; j < MAX_NUMT; j++)
				{
					currentSprite = SpritePool.getSprite();
					currentSprite.graphics.beginFill(0x990000);
					currentSprite.graphics.drawCircle(15, 15, 15);
					currentSprite.x = j * (currentSprite.width + 5);
					currentSprite.y = i * (currentSprite.width + 5);
					container.addChild( currentSprite );
				}
			}
			
			stage.addEventListener(MouseEvent.CLICK, removeDots);
//			stage.addEventListener(Event.ENTER_FRAME, TimeOut);
			var si:uint = setInterval(TimeOut2, 100)
				
			var myTimer:Timer=new Timer(100, 80); 
				
			myTimer.addEventListener("timer", TimeOut2);//注意，事件timer必须全部小写 
			
			myTimer.start(); 
			
			function removeDots(e:MouseEvent):void
			{
				while(container.numChildren > 0)
					SpritePool.disposeSprite(container.removeChildAt(0) as Sprite);
				clearInterval(si);
			}
			
			var t:int = 0;
			function TimeOut(e:Event):void
			{
				trace(++t / 10);
			}
			function TimeOut2():void
			{
				trace(++t / 10);
			}
		}
	}
}